package controllers

import (
	"monitor/models"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/cache"
)

type MainController struct {
	beego.Controller
}

func (this *MainController) Get() {
	this.Redirect("/stats?app=genome", 301)
}

type ClearController struct {
	beego.Controller
}

func (this *ClearController) Get() {

	app := this.GetString("app")
	if app != "" {
		keys, err := models.Rc.Do("KEYS", "*"+app+"|*")
		if err == nil {
			for _, key := range keys.([]interface{}) {
				models.Rc.Delete(cache.GetString(key))
				delete(models.Rates, cache.GetString(key))
			}
		}
		delete(models.Keys, app)
		this.Redirect("/stats?app="+app, 302)
	} else {
		models.Rc.ClearAll()
		this.Redirect("/", 302)
	}
}
